/**
 * PostQueryRequest
 */
export interface PostQueryRequest {
  /** 仅请求已发布文章 */ onlyPublished: boolean | null;
  /** 文章状态 */ status: string | null;
  /** 分类ID */ categoryId: number | null;
  search: string | null;
}

/**
 * PostPageData
 */
export interface PostPageData {
  rows: Array<Post>;
  total: number;
}

/**
 * Post
 */
export interface Post {
  id: number;
  title: string;
  cover: string;
  slug: string;
  status: string;
  summary: string;
  content: string;
  path: string;
  categoryId: number;
  category: CategoryDto;
}
/**
 * CategoryDto
 */
export interface CategoryDto {
  id: number;
  name: string;
  isVisible: boolean;
  parentId: number;
  status: ComStatus;
  sort: number;
  description: string;
}
export interface PostEditRequest {
  id: number | null;
  /** 标题 */ title: string | null;
  /** 文章链接，设置后可以通过以下形式访问文章 */ slug: string | null;
  /** 梗概 */ summary: string | null;
  /** 内容（markdown格式） */ content: string | null;
  /** 分类ID */ categoryId: number | null;
}
export interface PostInfoResult {
  id: number;
  /** 标题 */ title: string;
  /** 文章链接，设置后可以通过以下形式访问文章 */ slug: string;
  /** 梗概 */ summary: string;
  /** 内容（markdown格式） */ content: string;
  /** 分类ID */ categoryId: number;
}
/**
 * Category
 */
export interface Category {
  id: number;
  name: string;
  parentId: number;
  parent: Category;
  visible: boolean;
  posts: Array<Post>;
}

import { http } from "@/utils/http";
import { ComStatus } from "./model";

export class PostApi {
  /**
   * 无
   */
  public list(
    param: {
      sort?: number;
      sortField?: string;
      page?: number;
      limit?: number;
    },
    param1?: PostQueryRequest
  ): Promise<PostPageData> {
    return http.request({
      url: "/api/post/list",
      method: "post",
      data: param1,
      params: {
        Sort: param.sort,
        SortField: param.sortField,
        Page: param.page,
        Limit: param.limit
      }
    });
  }
  public getInfo(id?: number): Promise<PostInfoResult> {
    return http.request({
      url: "/api/post/getInfo",
      method: "post",
      params: { id }
    });
  }
  public edit(param1?: PostEditRequest): Promise<void> {
    return http.request({
      url: "/api/post/edit",
      method: "post",
      data: param1
    });
  }
}
export default new PostApi();
